/*
* @Author: zhaoxiaoyang
* @Date:   2016-08-26 11:17:58
* @Last Modified by:   zhaoxiaoyang
* @Last Modified time: 2020-06-20 18:00:47
*/

'use strict';

let os = require('os');
let IPv4Name = os.hostname();
let IpV4Addr;
let networkInterfaces = os.networkInterfaces();
// let servPort = 7250;
// let cdnPort = 8008;

/*
if (networkInterfaces().en0) {
	for(let i=0;i<networkInterfaces().en0.length;i++){
	    if(networkInterfaces().en0[i].family=='IPv4'){
	        IPv4=networkInterfaces().en0[i].address;
	    }
	}
};
*/

let test = require('dns').lookup(IPv4Name, function (err, add, fam) {
  	IpV4Addr = add
	console.log('local IP: '+IpV4Addr);
	console.log('local Name: '+IPv4Name);
});

for (let i in networkInterfaces){
    for (let m = 0, link = networkInterfaces[i], l = link.length; m < l; m++){
        if (link[m].family == 'IPv4' && link[m].address != '127.0.0.1') {
            IpV4Addr = link[m].address;
            break;
        }
    }
    if (IpV4Addr) break;
}

// IpV4Addr = IPv4Name || IpV4Addr || 'localhost'
IpV4Addr = IpV4Addr || IPv4Name || 'localhost'
// console.log('Web server IP: '+IpV4Addr);
// console.log('Web server Name: '+IPv4Name);

/**
 * [host exports]
 * @description     [host输出接口]
 * @type  {Object}
 * @param {String}  [localPath] [(X:/盘符) + localPath + src]
 */
module.exports = {
    // servPort: servPort,
    // cdnPort: cdnPort,
    IpV4: IpV4Addr,
    servUrl: 'http://'+IpV4Addr,
    cdnUrl: 'http://'+IpV4Addr,
    bash : 'view'
};